import { ApiProperty } from '@nestjs/swagger'
import {
  IsMobilePhone,
  IsOptional,
  IsString,
  IsNumber,
  IsInt,
  Max,
  Min,
  IsEmail,
  IsNotEmpty
} from 'class-validator'

import { BaseDto, BaseErrorDto as BaseError } from '../../apiProperty'
import { UserEntity } from '../../../entitys'

export * from '../../apiProperty'

export const BaseErrorDto = BaseError

export class UpdateUserDto {
  @ApiProperty({ example: 18, type: Number, required: false })
  @IsOptional()
  @IsNotEmpty({ message: 'age 不能为空' })
  @IsNumber({}, { message: 'age 参数必须是数字' })
  @IsInt({ message: 'age 必须是整数' })
  @Max(100, { message: 'age 太大' })
  @Min(18, { message: 'age 太小' })
  age: number

  @ApiProperty({ example: 1, type: Number, required: false })
  @IsOptional()
  @IsNotEmpty({ message: 'sex 不能为空' })
  @IsNumber({}, { message: 'sex 参数必须是数字' })
  @IsInt({ message: 'sex 必须是整数' })
  @Max(3, { message: 'sex 不合法' })
  @Min(0, { message: 'sex 不合法' })
  sex: number

  @ApiProperty({
    example: 'https://img01.yzcdn.cn/vant/apple-1.jpg',
    type: String,
    required: false
  })
  @IsOptional()
  @IsNotEmpty({ message: 'avatar 不能为空' })
  @IsString({ message: 'avatar 格式不正确' })
  avatar: string

  @ApiProperty({ example: '用户介绍', type: String, required: false })
  @IsOptional()
  @IsNotEmpty({ message: 'description 不能为空' })
  @IsString({ message: 'description 必须是字符' })
  description: string

  @ApiProperty({ example: '邮箱@qq.com', type: String, required: false })
  @IsOptional()
  @IsNotEmpty({ message: 'email 不能为空' })
  @IsEmail({}, { message: 'email 格式不正确' })
  email: string

  @ApiProperty({ example: '13488886666', type: String, required: false })
  @IsOptional()
  @IsNotEmpty({ message: 'mobile 不能为空' })
  @IsMobilePhone('zh-CN', {}, { message: 'mobile 格式不正确' })
  mobile: string

  @ApiProperty({ example: '用户昵称', type: String, required: false })
  @IsOptional()
  @IsNotEmpty({ message: 'nickname 不能为空' })
  @IsString({ message: 'nickname 格式不正确' })
  nickname: string
}

export class UserResponseDto extends BaseDto {
  @ApiProperty()
  data: UserEntity
}

export class ResponseDto extends BaseDto {
  @ApiProperty({ example: {} })
  data: {}
}
